//
//  CheckTechnicianInfromation.m
//  XJMCustomer
//
//  Created by Mr.hu on 2017/10/12.
//  Copyright © 2017年 Mr.hu. All rights reserved.
//

#import "CheckTechnicianInfromation.h"
#import "FirstCheckTechnicianCell.h"

#import "SecondCheckTableViewCell.h"
#import "ThreeCheckInformationCell.h"
#import "FourAppraiseCheckCell.h"
#import "FiveAppraiseDetailCell.h"

#import "ScrollViewImage.h"
#import <WebKit/WebKit.h>
#import "YGBanner.h"
#import <UShareUI/UShareUI.h>

@interface CheckTechnicianInfromation ()<UITableViewDelegate,UITableViewDataSource,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,WKUIDelegate,WKNavigationDelegate>

@property (weak, nonatomic) IBOutlet UITableView *CheckPersonTableview;

/** 注释 **/
@property (strong, nonatomic) UICollectionViewFlowLayout * collecFlowLayOut;
/** 注释 **/
@property (strong, nonatomic) UIButton * Collectbtn;
/** 注释 **/
@property (strong, nonatomic) NSArray * AllAppraise; //技师所有的评价
/** 注释 **/
@property (strong, nonatomic) NSDictionary * AllTechnicanMessage; //技师信息
/** 注释 **/
@property (strong, nonatomic) NSMutableArray * photos_urlArr;
/** 注释 **/
@property (strong, nonatomic) SecondCheckTableViewCell * Secondfriend;
/** 注释 **/
@property (strong, nonatomic) WKWebView * webViwe;
@property (nonatomic,strong) NSDictionary * Appraisedict;
/** 注释 **/
@property (strong, nonatomic) YGBanner * banner;
@property (nonatomic) NSInteger page;
@property (nonatomic ,strong)AVPlayerLayer * playerLayer;
@property (nonatomic ,strong)AVPlayer * player;
@property (nonatomic ,strong)AVPlayerItem * playerItem;

@end

@implementation CheckTechnicianInfromation

- (void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:NO];
    
}

- (void)adjustUI
{
    self.CheckPersonTableview.tableFooterView = [[UIView alloc] init];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"个人主页";
    [self addRightBtn:[UIImage imageNamed:@"fenxiang"] Action:@selector(SharePersonView)];
    
    [self adjustUI];
    
    self.page = 1;
    
    self.CheckPersonTableview.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(requestServerData)];
    self.CheckPersonTableview.mj_header.automaticallyChangeAlpha = NO;
    [self.CheckPersonTableview.mj_header beginRefreshing];
    
    self.photos_urlArr = [NSMutableArray array];
    self.AllAppraise = [NSArray array];
    
    
    //设置用户自定义的平台
    [UMSocialUIManager setPreDefinePlatforms:@[@(UMSocialPlatformType_WechatSession),
                                               @(UMSocialPlatformType_WechatTimeLine),
                                               @(UMSocialPlatformType_QQ),
                                               @(UMSocialPlatformType_Qzone),
                                               @(UMSocialPlatformType_Sina),]];
    
}

- (void)SharePersonView{
    
    [UMSocialUIManager showShareMenuViewInWindowWithPlatformSelectionBlock:^(UMSocialPlatformType platformType, NSDictionary *userInfo) {
        // 根据获取的platformType确定所选平台进行下一步操作
        
        //创建分享消息对象
        UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
        
        //创建网页内容对象
        NSString* thumbURL =  [NSString stringWithFormat:@"https://api.xijiaomo.com/tech.php/share/wap?tid=%@",[XJToolClass getUserId]];
        UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:@"个人主页" descr:[NSString stringWithFormat:@"%@的个人主页",[XJToolClass getNickname]] thumImage:thumbURL];
        //设置网页地址
        
        shareObject.webpageUrl = [NSString stringWithFormat:@"https://api.xijiaomo.com/tech.php/share/wap?tid=%@",[XJToolClass getUserId]];
        
        //分享消息对象设置分享内容对象
        messageObject.shareObject = shareObject;
        //调用分享接口
        [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
            if (error) {
                UMSocialLogInfo(@"************Share fail with error %@*********",error);
            }else{
                if ([data isKindOfClass:[UMSocialShareResponse class]]) {
                    UMSocialShareResponse *resp = data;
                    //分享结果消息
                    UMSocialLogInfo(@"response message is %@",resp.message);
                    //第三方原始返回的数据
                    UMSocialLogInfo(@"response originalResponse data is %@",resp.originalResponse);
                    
                }else{
                    UMSocialLogInfo(@"response data is %@",data);
                }
            }
            [self alertWithError:error];
        }];
        
    }];
}

- (void)alertWithError:(NSError *)error
{
    NSString *result = nil;
    if (!error) {
        result = [NSString stringWithFormat:@"Share succeed"];
    }
    else{
        NSMutableString *str = [NSMutableString string];
        if (error.userInfo) {
            for (NSString *key in error.userInfo) {
                [str appendFormat:@"%@ = %@\n", key, error.userInfo[key]];
            }
        }
        if (error) {
            result = [NSString stringWithFormat:@"Share fail with error code: %d\n%@",(int)error.code, str];
        }else{
            result = [NSString stringWithFormat:@"Share fail"];
        }
    }
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"share"
                                                    message:result
                                                   delegate:nil
                                          cancelButtonTitle:NSLocalizedString(@"sure", @"确定")
                                          otherButtonTitles:nil];
    [alert show];
}


#pragma mark -- 请求数据
- (void)requestServerData{
    
    [XJHttpClass TeachPersonalHomePageToken:[XJToolClass getToken] andFinishblock:^(id response, NSString *errStr) {
        
        [self.CheckPersonTableview.mj_header endRefreshing];
        
        if (errStr) {
            [XJToolClass tipAnimationWith:errStr];
        }else{
            
            [self checkTblaViewController];
            self.AllTechnicanMessage = response[@"data"];
            
            //1没有收藏 0已收藏
            if ([self.AllTechnicanMessage[@"is_collect"] isEqualToString:@"1"]) {
                [self.Collectbtn setImage:[UIImage imageNamed:@"iconnotget"] forState:UIControlStateNormal];
                [self.Collectbtn addTarget:self action:@selector(CollectionInformation) forControlEvents:UIControlEventTouchUpInside];
            }else{
                
                [self.Collectbtn setImage:[UIImage imageNamed:@"iconget"] forState:UIControlStateNormal];
                self.Collectbtn.selected = YES;
                [self.Collectbtn addTarget:self action:@selector(CollectionInformation) forControlEvents:UIControlEventTouchUpInside];
            }
            
            //获取技师评价
            [XJHttpClass receiveTechCommenttoken:[XJToolClass getToken] page:[NSString stringWithFormat:@"%ld",_page] andFinishblock:^(id response, NSString *errStr) {
                
                if (errStr) {
//                    [XJToolClass tipAnimationWith:errStr];
                }else{
                    
                    self.Appraisedict = response[@"data"];
                    if ([self.Appraisedict isKindOfClass:[NSDictionary class]]) {
                        self.AllAppraise = self.Appraisedict[@"appraise_list"];
                    }
                    
                    if (self.Appraisedict.count) {
                        self.CheckPersonTableview.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
                            [self AwaitDealOrderRequestPullDown: ++ self.page];
                            [self.CheckPersonTableview.mj_footer endRefreshing];
                        }];
                    }
                    
                    [self.CheckPersonTableview reloadData];
                }
            }];
            
            [self.CheckPersonTableview reloadData];
            [self.Secondfriend.SecondCheckCollectionView reloadData];
        }
    }];
}

-(void)AwaitDealOrderRequestPullDown:(NSInteger)page{
    {
        //获取技师评价
        [XJHttpClass receiveTechCommenttoken:[XJToolClass getToken] page:[NSString stringWithFormat:@"%ld",page] andFinishblock:^(id response, NSString *errStr) {
            
            [LoadingView hide];
            
            if (errStr) {
                [self.CheckPersonTableview.mj_footer endRefreshingWithNoMoreData];
            }else{
                
                NSMutableArray * arrmut = response[@"data"];
                if (arrmut.count > 0) {
                    self.Appraisedict = response[@"data"];
                    self.AllAppraise = self.Appraisedict[@"appraise_list"];
                    
                    [self.CheckPersonTableview reloadData];
                }else{
                    [self.CheckPersonTableview.mj_footer endRefreshingWithNoMoreData];
                }
            }
        }];
        
        [self.CheckPersonTableview reloadData];
        [self.Secondfriend.SecondCheckCollectionView reloadData];
    }
    
}

- (void)CollectionInformation{
    
    if (self.Collectbtn.selected == NO) {
        
        [self.Collectbtn setImage:[UIImage imageNamed:@"iconget"] forState:UIControlStateNormal];
        self.Collectbtn.selected = YES;
        
        if (self.TechnicianId) {
            
        }else{
            
            [self.Collectbtn setImage:[UIImage imageNamed:@"iconnotget"] forState:UIControlStateNormal];
            self.Collectbtn.selected = NO;
            
        }
    }
}

- (void)checkTblaViewController{
    
    self.CheckPersonTableview.delegate = self;
    self.CheckPersonTableview.dataSource = self;
    self.CheckPersonTableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self.CheckPersonTableview registerNib:[UINib nibWithNibName:@"FirstCheckTechnicianCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"FirstCheckTechnicianCell"];
    
    [self.CheckPersonTableview registerNib:[UINib nibWithNibName:@"SecondCheckTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"SecondCheckTableViewCell"];
    [self.CheckPersonTableview registerNib:[UINib nibWithNibName:@"ThreeCheckInformationCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"ThreeCheckInformationCell"];
    [self.CheckPersonTableview registerNib:[UINib nibWithNibName:@"FourAppraiseCheckCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"FourAppraiseCheckCell"];
    [self.CheckPersonTableview registerNib:[UINib nibWithNibName:@"FiveAppraiseDetailCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"FiveAppraiseDetailCell"];
}

#pragma mark - TableViewDatasource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{   //5
    return 5+1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0 || section ==1 ||section ==2 || section ==3 || section ==4 ) {
        return 1;
    }else{
        return self.AllAppraise.count;
    }
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) { //头像
        FirstCheckTechnicianCell * friend=[tableView dequeueReusableCellWithIdentifier:@"FirstCheckTechnicianCell" forIndexPath:indexPath];
        friend.selectionStyle = UITableViewCellSelectionStyleNone;
        friend.userInteractionEnabled = YES;
        
        NSString * imagestr = [NSString stringWithFormat:@"%@",self.AllTechnicanMessage[@"headurl"]];
        [friend.CheckHeadImage sd_setImageWithURL:[NSURL URLWithString:imagestr]];
        friend.CheckHeadImage.layer.cornerRadius = 41.5;
        friend.CheckHeadImage.layer.masksToBounds = YES;
        
        friend.CheckTechName.text = self.AllTechnicanMessage[@"truename"];
        
        if (self.Appraisedict[@"all_appraise"]) {
            
            friend.Check_CommentNumber.text = [NSString stringWithFormat:@"共有%@条评价",self.Appraisedict[@"all_appraise"]];
            friend.Check_Appraise.text  =  [NSString stringWithFormat:@"好感度%@%%",self.Appraisedict[@"good_praise"]];
            
            friend.Check_CommentNumber.layer.borderColor = [UIColor whiteColor].CGColor;
            friend.Check_CommentNumber.layer.borderWidth = 1;
            friend.Check_CommentNumber.layer.masksToBounds = YES;
            friend.Check_CommentNumber.layer.cornerRadius = 3;
            friend.Check_CommentNumber.textColor = [UIColor whiteColor];
            friend.Check_Appraise.layer.borderColor = [UIColor whiteColor].CGColor;
            friend.Check_Appraise.layer.borderWidth = 1;
            friend.Check_Appraise.layer.masksToBounds = YES;
            friend.Check_Appraise.layer.cornerRadius = 3;
            friend.Check_Appraise.textColor = [UIColor whiteColor];
            
        }else{
            friend.Check_CommentNumber.text = [NSString stringWithFormat:@"共有0条评价"];
            friend.Check_Appraise.text  =  [NSString stringWithFormat:@"好评度：0%%"];
            
            friend.Check_CommentNumber.layer.borderColor = [UIColor whiteColor].CGColor;
            friend.Check_CommentNumber.layer.borderWidth = 1;
            friend.Check_CommentNumber.layer.masksToBounds = YES;
            friend.Check_CommentNumber.layer.cornerRadius = 3;
            friend.Check_CommentNumber.textColor = [UIColor whiteColor];
            friend.Check_Appraise.layer.borderColor = [UIColor whiteColor].CGColor;
            friend.Check_Appraise.layer.borderWidth = 1;
            friend.Check_Appraise.layer.masksToBounds = YES;
            friend.Check_Appraise.layer.cornerRadius = 3;
            friend.Check_Appraise.textColor = [UIColor whiteColor];
        }
        
        //后期加背景图片
        //        [friend.CheckBackgroundImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@""]]];
        
        return friend;
        
    }else if (indexPath.section == 1){ //相册
        SecondCheckTableViewCell * friend=[tableView dequeueReusableCellWithIdentifier:@"SecondCheckTableViewCell" forIndexPath:indexPath];
        friend.selectionStyle = UITableViewCellSelectionStyleNone;
        friend.userInteractionEnabled = YES;
        
        self.collecFlowLayOut = [[UICollectionViewFlowLayout alloc]init];
        self.collecFlowLayOut.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        
        friend.SecondCheckCollectionView.delegate = self;
        friend.SecondCheckCollectionView.dataSource = self;
        friend.SecondCheckCollectionView.showsHorizontalScrollIndicator = NO;
        friend.SecondCheckCollectionView.alwaysBounceHorizontal = NO;
        friend.SecondCheckCollectionView.scrollsToTop = NO;
        [friend.SecondCheckCollectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"MYCollectionViewCell"];
        
        NSMutableArray * alltech = self.AllTechnicanMessage[@"photos_url"];
        
        if (alltech.count > 0) {
            
            [self.photos_urlArr removeAllObjects];
            [alltech enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                
                if ([obj isKindOfClass:[NSNull class]]) {
                    /**
                     *  @brief  此处直接移除null，而不是替换为字符串
                     *  替换成字符串可能导致程序闪退，原因：原本是要NSArray或者NSDictionary对象，我们替换成NSString对象，导致读取出错而闪退
                     */
                    [alltech removeObjectAtIndex:idx];
                }
                [self.photos_urlArr addObject:obj[@"pic_url"]];
            }];
            
        }
        NSMutableArray * Videomut = self.AllTechnicanMessage[@"video_url"];
        if (Videomut.count > 0) {
            [self.photos_urlArr addObject:self.AllTechnicanMessage[@"video_url"][0][@"video_pic"]];
        }
        
        return friend;
        
    }else if (indexPath.section == 2){
        ThreeCheckInformationCell * friend=[tableView dequeueReusableCellWithIdentifier:@"ThreeCheckInformationCell" forIndexPath:indexPath];
        friend.selectionStyle = UITableViewCellSelectionStyleNone;
        friend.userInteractionEnabled = YES;
        [friend.ThreeCheckImage setImage:[UIImage imageNamed:@"jianjie"]];
        friend.ThreeInformationLab.text = @"服务项目";
        friend.ThreeSubInformationlab.text = self.AllTechnicanMessage[@"desc"];
        friend.ThreeSubInformationlab.textColor = RGBA(153, 153, 153, 1);
        
        return friend;
        
    }else if (indexPath.section == 3){
        ThreeCheckInformationCell * friend=[tableView dequeueReusableCellWithIdentifier:@"ThreeCheckInformationCell" forIndexPath:indexPath];
        friend.selectionStyle = UITableViewCellSelectionStyleNone;
        friend.userInteractionEnabled = YES;
        [friend.ThreeCheckImage setImage:[UIImage imageNamed:@"renzheng"]];
        friend.ThreeInformationLab.text = @"手机认证";
        friend.ThreeSubInformationlab.text = self.AllTechnicanMessage[@"mobile"];
        friend.ThreeSubInformationlab.textColor = RGBA(153, 153, 153, 1);
        
        return friend;
        
    }else if (indexPath.section == 4){
        FourAppraiseCheckCell * friend=[tableView dequeueReusableCellWithIdentifier:@"FourAppraiseCheckCell" forIndexPath:indexPath];
        friend.selectionStyle = UITableViewCellSelectionStyleNone;
        
        if ([self.Appraisedict isKindOfClass:[NSDictionary class]]) {
            
            friend.UserCommentLab.text = [NSString stringWithFormat:@"用户评价（%@）条",self.Appraisedict[@"all_appraise"]];
            //        friend.AppraiseLab.text = [NSString stringWithFormat:@"好评率：%@%%",self.Appraisedict[@"good_praise"]];
        }
        
        /*
         UIButton * but;
         int i;
         CGFloat w = 0; //保存前一个button的宽以及前一个button距离屏幕边缘的距离
         CGFloat h = 50; //用来控制button距离父视图的高
         
         NSArray * array = self.AllTechnicanMessage[@"comment_tag"];
         
         
         if (array.count > 0) {
         
         for (i = 0; i < array.count; i++) {
         
         but =[[UIButton alloc]init];
         
         but.layer.cornerRadius = 10;
         but.layer.masksToBounds = YES;
         but.tag = i;
         [but setTitleColor:[UIColor colorWithRed:80.0/255.0 green:80.0/255.0 blue:80.0/255.0 alpha:1.0] forState:UIControlStateNormal];
         [but setBackgroundColor:RGBA(255, 244, 226, 1)];
         but.titleLabel.textAlignment = NSTextAlignmentCenter;
         but.titleLabel.font = [UIFont systemFontOfSize:11];
         NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:12]};
         CGFloat length = [array[i][@"tag_name"] boundingRectWithSize:CGSizeMake(320, 200) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil].size.width;
         
         //为button赋值
         [but setTitle:array[i][@"tag_name"] forState:UIControlStateNormal];
         
         //设置button的frame
         but.frame = CGRectMake(20 + w, 10, length + 40 , 30);
         
         //当button的位置超出屏幕边缘时换行 320 只是button所在父视图的宽度
         if(15 + w + length + 15 > 320){
         w = 0; //换行时将w置为0
         h = h + but.frame.size.height + 20;//距离父视图也变化
         but.frame = CGRectMake(20 + w, 10, length + 40, 30);//重设button的frame
         }
         
         if (i >= 6) {
         
         //设置button的frame
         but.frame = CGRectMake(20 + w, 180, length + 40 , 30);
         
         }
         w = but.frame.size.width + but.frame.origin.x;
         
         [friend.SelectItemView addSubview:but];
         
         }
         }
         */
        
        friend.userInteractionEnabled = YES;
        return friend;
        
    }else {
        
        FiveAppraiseDetailCell * friend=[tableView dequeueReusableCellWithIdentifier:@"FiveAppraiseDetailCell" forIndexPath:indexPath];
        if(friend==nil){
            friend=[[FiveAppraiseDetailCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"FiveAppraiseDetailCell"];
        }
        friend.selectionStyle = UITableViewCellSelectionStyleNone;
        friend.AppraiseHeadImage.layer.cornerRadius = 15;
        friend.AppraiseHeadImage.layer.masksToBounds = YES;
        
        friend.userInteractionEnabled = YES;
        
        [friend setData:self.AllAppraise[indexPath.row]];
        return friend;
    }
}

#pragma mark TableViewDelegate
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return 180;
    }else if (indexPath.section ==1){
        return 100+8;
    }else if (indexPath.section ==2){
        return 50;
    }else if (indexPath.section ==3){
        return 50;
    }else if (indexPath.section == 4){
        return 50;
    }else{
        return 100;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    //当手指离开某行时，就让某行的选中状态消失
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
}

#pragma mark-- CollectionView
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    //有多少个相册就加多少个
    //    return self.photos_urlArr.count;
    //    NSArray * alltech = self.AllTechnicanMessage[@"photos_url"];
    return self.photos_urlArr.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MYCollectionViewCell" forIndexPath:indexPath];
    
    UIImage * thumbiamge = [[UIImage alloc]init];
    NSDictionary * techvideo = self.AllTechnicanMessage[@"video_url"];
    if ([techvideo isKindOfClass:[NSDictionary class]]) {
        
        AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",techvideo[@"video_pic"]]] options:nil];
        NSParameterAssert(asset);
        AVAssetImageGenerator *assetImageGenerator =[[AVAssetImageGenerator alloc] initWithAsset:asset];
        assetImageGenerator.appliesPreferredTrackTransform = YES;
        assetImageGenerator.apertureMode = AVAssetImageGeneratorApertureModeEncodedPixels;
        CGImageRef thumbnailImageRef = NULL;
        CFTimeInterval thumbnailImageTime = 1;
        NSError *thumbnailImageGenerationError = nil;
        thumbnailImageRef = [assetImageGenerator copyCGImageAtTime:CMTimeMake(thumbnailImageTime, 60)actualTime:NULL error:&thumbnailImageGenerationError];
        if(!thumbnailImageRef)
            
            thumbiamge = thumbnailImageRef ? [[UIImage alloc]initWithCGImage: thumbnailImageRef] : nil;
        [self.photos_urlArr addObject:thumbiamge];
    }
    
    
    UIButton * FirstBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 57, 57)];
    FirstBtn.tag = indexPath.item;
    [FirstBtn addTarget:self action:@selector(CollectionMethOnclicked:) forControlEvents:UIControlEventTouchUpInside];
    if (indexPath.item == self.photos_urlArr.count) {
        [FirstBtn setImage:thumbiamge forState:UIControlStateNormal];
    }else{
        NSString * imagestr = [[NSString stringWithFormat:@"%@",self.photos_urlArr[indexPath.item]]stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
        [FirstBtn sd_setImageWithURL:[NSURL URLWithString:imagestr] forState:UIControlStateNormal];
    }
    
    [FirstBtn addTarget:self action:@selector(videoplayerMeth:) forControlEvents:UIControlEventTouchUpInside];
    [cell addSubview:FirstBtn];
    
    return cell;
}

- (void)videoplayerMeth:(UIButton *)sender{
    
    
}

- (void)CollectionMethOnclicked:(UIButton*)sender{
    
    if (self.photos_urlArr.count>2) {
        
        __weak typeof(self)weakSelf = self;
        _banner = [[YGBanner alloc] initWithFrame:CGRectMake(0,0, ScreenWidth, ScreenHeight) imageNames:self.photos_urlArr imageHandle:^(NSInteger index) {
            
            [self dismissViewControllerAnimated:YES completion:^{
            }];
            
            if (index == self.photos_urlArr.count-1) {
                
                NSMutableArray * videoarr = self.AllTechnicanMessage[@"video_url"];
                NSString * videostr = videoarr[0][@"video_url"];
                
                _player = [AVPlayer playerWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",videostr]]];
                [self.player play];
                AVPlayerLayer *layer = [AVPlayerLayer playerLayerWithPlayer:self.player];
                layer.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
                [self.view.layer addSublayer:layer];
                [self.player pause];
                
            }else{
                
            }
            [weakSelf.banner removeFromSuperview];
            
        }];
        
        [self.view addSubview:_banner];
    }
}

//- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
//
//    [super touchesBegan:touches withEvent:event];
//    [self.banner removeFromSuperview];
//}

#pragma 设置Item之间的纵向间距
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 8;
}

#pragma 设置Item之间的横向间距
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 15;
}

//返回单元格的尺寸大小
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(57, 57);
}


-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    
    
}


@end
